package org.bagou.proj.main

import android.content.Context
import android.widget.Toast
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ApplicationComponent
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import javax.inject.Singleton

@Module
@InstallIn(ApplicationComponent::class)
abstract class MainModule {

//    @ActivityScoped Activity作用域内单例
    // @Singleton 全局单例
    @Binds
    @Singleton
    abstract fun bindService(impl:LoginServiceImpl):ILogService

//    @Provides
//    fun bindService():ILogService {
//        return LoginServiceImpl(context)
//    }
}

interface ILogService {
    fun login()
}

class LoginServiceImpl @Inject constructor(@ApplicationContext val context:Context):ILogService{
    override fun login() {
        Toast.makeText(context, "尝试使用依赖注入~", Toast.LENGTH_SHORT).show()
    }

}